package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import liquibase.pro.packaged.A;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MeetingManagement;
import com.ruoyi.system.service.IMeetingManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会议管理Controller
 *
 * @author ruoyi
 * @date 2024-04-02
 */
@RestController
@RequestMapping("/system/management")
public class MeetingManagementController extends BaseController
{
    @Autowired
    private IMeetingManagementService meetingManagementService;

    /**
     * 查询会议管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody MeetingManagement meetingManagement)
    {
        setStartPage(meetingManagement.getPageNum(),meetingManagement.getPageSize());
        List<MeetingManagement> list = meetingManagementService.selectMeetingManagementList(meetingManagement);
        return getDataTable(list);
    }

    /**
     * 获取会议管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:management:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(meetingManagementService.selectMeetingManagementById(id));
    }

    /**
     * 新增会议管理
     */
    @PreAuthorize("@ss.hasPermi('system:management:add')")
    @Log(title = "会议管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MeetingManagement meetingManagement)
    {
        meetingManagement.setCreateBy(String.valueOf(getUserId()));
        return meetingManagementService.insertMeetingManagement(meetingManagement);
    }

    /**
     * 修改会议管理
     */
    @PreAuthorize("@ss.hasPermi('system:management:edit')")
    @Log(title = "会议管理", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody MeetingManagement meetingManagement)
    {
        meetingManagement.setUpdateBy(getUsername());
        return toAjax(meetingManagementService.updateMeetingManagement(meetingManagement));
    }

    /**
     * 删除会议管理
     */
    @PreAuthorize("@ss.hasPermi('system:management:remove')")
    @Log(title = "会议管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(meetingManagementService.deleteMeetingManagementById(id));
    }

    /**
     * 查询会议会议签到统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @PostMapping("/signaturelist")
    public TableDataInfo signaturelist(@RequestBody MeetingManagement meetingManagement)
    {
        setStartPage(meetingManagement.getPageNum(),meetingManagement.getPageSize());
        List<MeetingManagement> list = meetingManagementService.selectMeetingSignaturelist(meetingManagement);
        return getDataTable(list);
    }

    /**
     * 导出会议通知
     */
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @PostMapping("/exportNotify")
    public void exportNotify(@RequestBody MeetingManagement meetingManagement,HttpServletResponse response)
    {
        meetingManagementService.exportMeetingNotify(meetingManagement,response);
    }

    /**
     * 导出会议签到列表
     */
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @PostMapping("/exportSignature")
    public void exportSignature(@RequestBody MeetingManagement meetingManagement,HttpServletResponse response)
    {
        meetingManagementService.exportMeetingSignature(meetingManagement,response);
    }

    /**
     * 党建大数据 会议分布
     */
    @GetMapping("/meetingStructure/{queryYear}")
    public AjaxResult meetingStructure(@PathVariable String queryYear)
    {
        if(StringUtils.isBlank(queryYear)){
            queryYear = DateUtils.getNowYear();
        }
        return success(meetingManagementService.meetingStructure(queryYear));
    }
}
